﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace RTGS.Library.Report
{
    public class ReportStpLog
    {

        private string errorLog;
        private string connectionString;

        public ReportStpLog(string ConnectionString)
        {
            errorLog = string.Empty;
            connectionString = ConnectionString;
        }

        public DataTable GetReportStpLog()
        {
            DataTable dt = new DataTable();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
SELECT [LOGDATETIME]
      ,[LOGLOGGER]
      ,[LOGLEVEL]
      ,[LOGTHREAD]
      ,[LOGMESSAGE]
      ,[LOGEXCEPTION]
  FROM [STP_LOG] ";

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    try
                    {
                        conn.Open();
                        da.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        errorLog = ex.Message;
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }

            return dt;

        }

    }
}
